//
//  LGFLeftRowButton.swift
//  MedicalUnion
//
//  Created by apple on 2019/9/2.
//  Copyright © 2019 William_Xue. All rights reserved.
//

import UIKit

protocol LGFLeftRowButtonDelegate: class {
    func leftRowButtonSelect(_ view: LGFLeftRowButton) -> Void
}

class LGFLeftRowButton: UIView {
    
    weak var delegate: LGFLeftRowButtonDelegate?
    
    var button: UIButton!
    var leftLine: UIView!

    var textFont: UIFont!
    var titleStr: String!
    var textColor: UIColor!
    var leftLineHeight: CGFloat! {// 底部线左侧距离
        didSet {
            if leftLine != nil {
                leftLine.snp.updateConstraints { (make) in
                    make.height.equalTo(leftLineHeight.lgf_H())
                }
            }
        }
    }
    
    class func lgf(text: String,
                   font: UIFont,
                   textColor: UIColor,
                   leftLineHeight: CGFloat) -> LGFLeftRowButton {
        let view: LGFLeftRowButton = LGFLeftRowButton.init()
        view.leftLineHeight = leftLineHeight
        view.lgf_ViewName = text
        view.textColor = textColor
        view.titleStr = text
        view.textFont = font
        view.backgroundColor = EWEDarkMode.white()
        view.translatesAutoresizingMaskIntoConstraints = false
        view.configView()
        return view
    }
    
    func configView() {
        button = UIButton.init(type: .custom)
        button.setTitle(titleStr, for: .normal)
        button.titleLabel?.font = textFont
        button.setTitleColor(textColor, for: .normal)
        button.addTarget(self, action: #selector(bottomBtnSelect(_:)), for: .touchUpInside)
        addSubview(button)
        button.lgf_FillSuperview()
        
        leftLine = UIView.init()
        leftLine.backgroundColor = EWEDarkMode.color_F1F2F4()
        addSubview(leftLine)
        leftLine.snp.makeConstraints { (make) in
            make.right.equalToSuperview()
            make.centerY.equalToSuperview()
            make.height.equalTo(leftLineHeight.lgf_H())
            make.width.equalTo(0.5)
        }
    }

    @objc func bottomBtnSelect(_ sender: UIButton) {
        self.delegate?.leftRowButtonSelect(self)
    }
}
